import {Util,GridMixin} from '@lowcode/jpaas-base-lib';
import vuedraggable from "vuedraggable";
import MeasureConf from "@/views/modules/design/dialog/measure-conf.vue";
import DateSetting from "@/views/modules/design/dialog/date-setting.vue";
import NumericalMeasurement from "./numerical-measurement.vue"
import FieldRenderSetting from "@/views/modules/design/dialog/field-render-setting.vue";
import IndicatorMax from "@/views/modules/design/dialog/indicator-max.vue";
import ResultRowConfig from "@/views/modules/design/right-component/common/result-row-config.vue";
import SettingDialog from "@/views/modules/design/dialog/setting-dialog.vue";

/**
 * 基础配置
 */
export default {
	components:{
		vuedraggable,
        ResultRowConfig
	},
    mixins: [GridMixin],
	props:{
		config:{
			type:Object
		},
		modelConfig:{
			type:Object
		},
		isDialog:{
			type:Boolean,
			default:false
		}
	},
	data() {
		return {
			//不显示颜色图例的图表类型
			notShowLegend:["pieChart","ringChart","funnelChart","gaugeChart","multiColorGauge","lineBar","map","radar"],
			//不显示交互过滤条件的图表类型
			notShowFilter:["map"],
			//不显示维度
			notShowDimensions:["gaugeChart","multiColorGauge"],
			//显示xy轴文字
			showXY:["generalBar","horizontalBar","stackedBar","lineChart","areaChart","stackedArea","lineBar"],
			//删除维度id
			dimensionId:null,
			//删除度量设置id
			measuresId:null,
			//删除度量设置id
			measures2Id:null,
			//删除 颜色图例Id
			colorLegendId:null,
			//删除 过滤Id
			filterId:null,
			//拖入纬度设置删除
			latitude:null
		}
	},
	created() {
		//开启双y轴
		if(this.config.styles.yAxisShow2 && !this.config.dataSources.measures2){
            this.config.dataSources["measures2"]=[];
		}
	},
	methods:{
		i18n(name, text, key) {
			return this.$ti18(name, text, "chartLang.common", key);
		},
		//鼠标移上去显示删除维度设置
		mouseenter(index,type,idx){
			if(type =='measures'){
				this.measuresId = index;
			} else if(type =='measures2') {
				this.measures2Id = index;
			}else if(type =='colorLegend') {
				this.colorLegendId = index;
			}else if(type =='dimensions'){
				this.dimensionId = index;
			}else  if(type =='latitude'){
				this.latitude =index;
			}else if(type =='filterParams'){
				this.filterId=index
			}
		},
		mouseleave(name,type){
			if(type =='measures'){
				this.measuresId = name;
			}else if(type =='measures2') {
				this.measures2Id = name;
			}else if(type =='colorLegend') {
				this.colorLegendId = name;
			}else if(type =='dimensions'){
				this.dimensionId = name;
			} else  if(type =='latitude'){
				this.latitude = name
			}else if(type =='filterParams'){
				this.filterId = name;
			}
		},
		up(index,type){
			let rows=[];
			if(type =='dimensions'){
				rows=this.config.dataSources.dimensions;
			}
			else if(type =='colorLegend') {
				rows=this.config.dataSources.colorLegends;
			}
			else if(type =='measures') {
				rows=this.config.dataSources.measures;
			}else if(type =='measures2') {
				rows=this.config.dataSources.measures2;
			}
			this.toUp(rows,index);
		},
		down(index,type){
			let rows=[];
			if(type =='dimensions'){
				rows=this.config.dataSources.dimensions;
			}
			else if(type =='colorLegend') {
				rows=this.config.dataSources.colorLegends;
			}
			else if(type =='measures') {
				rows=this.config.dataSources.measures;
			}else if(type =='measures2') {
				rows=this.config.dataSources.measures2;
			}
			this.toDown(rows,index);
		},
		//维度/度量删除
        dimensionDelete(index,type){
			if(type =='dimensions'){
				this.config.dataSources.dimensions.splice(index,1);
			}
			else if(type =='colorLegend') {
				this.config.dataSources.colorLegends.splice(index,1);
			}
			else if(type =='measures') {
				this.config.dataSources.measures.splice(index,1);
			}else if(type =='measures2') {
				this.config.dataSources.measures2.splice(index,1);
			}else if(type =='filterParams') {
				this.config.dataSources.filterParams.splice(index,1);
			}
		},
		setMeasureConf(measure,index,type,config,title){
			let self=this;
			Util.open({
				component: MeasureConf,
				curVm: this,
				widthHeight: ['600px', '420px'],
				title:title || this.i18n('metricSet','度量设置'),
				zIndex: 10000,
				data:{
					measure:measure,
					config:config,
				}
			}, function (action, data) {
				if (action != 'ok') return;
				if(type =='measures') {
                    self.config.dataSources.measures[index]=data;
				}else if(type =='measures2'){
                    self.config.dataSources.measures2[index]=data;
				}
			});
		},
		dateSetting(item,index){
			let self=this;
			Util.open({
				component: DateSetting,
				curVm: this,
				widthHeight: ['600px', '420px'],
				title:this.i18n('dateSetting','日期设置'),
				zIndex: 10000,
				data:{
					dimension:item
				}
			}, function (action, data) {
				if (action != 'ok') return;
                self.config.dataSources.dimensions[index]=data;
			});
		},
		//设置指数
		setIndicatorMax(fieldSetting,index){
			let self=this;
			let baseConf = {
				curVm: this,
				widthHeight: ['800px', '600px'],
				zIndex: 9999,
				component:IndicatorMax,
				title:this.i18n('maximum','设置指数最大值'),
				shade:true,
				data:{
					fieldSetting: fieldSetting
				}
			};
			Util.open(baseConf, function (action,data) {
				if (action != 'ok') return;
                self.config.dataSources.dimensions[index]["indicatorMax"]=data;
			})
		},
		setNumericalMeasurement(measure,index,type){
			let self=this;
			Util.open({
				component: NumericalMeasurement,
				curVm: this,
				widthHeight: ['700px', '500px'],
				title:this.i18n('metricSet','度量设置') ,
				zIndex: 10000,
				data:{
					measure:measure
				}
			}, function (action, data) {
				if (action != 'ok') return;
				if(type =='measures') {
                    self.config.dataSources.measures[index]=data;
				}else if(type =='measures2'){
                    self.config.dataSources.measures2[index]=data;
				}
			});
		},
		//维度字段渲染
		setFieldRender(fieldSetting){
			let self=this;
			let baseConf = {
				curVm: this,
				widthHeight: ['800px', '600px'],
				zIndex: 9999,
				component: FieldRenderSetting,
				title:this.i18n('fieldRender','字段渲染'),
				shade:true,
				data:{
					fieldSetting:fieldSetting,
					modelConfig:this.modelConfig,
				}
			};
			Util.open(baseConf, function (action,setting) {
				if (action != 'ok') return;
                fieldSetting["renderSetting"]=setting;
			})
		},
        //图标
        getIcon(obj) {
            if (obj.dataType == 'string') {
                return 'icon-lineField-String';
            } else if (obj.dataType == 'date') {
                return 'icon-lineriqi2';
            } else  {
                return 'icon-lineshuzi';
            }
        },
        setSetting(item,index,type){
            let self=this;
            Util.open({
                component: SettingDialog,
                curVm: this,
                widthHeight: ['600px', '420px'],
                title:"设置",
                zIndex: 10000,
                data:{
                    settingConfig:item,
                    type:this.config.chartType
                }
            }, function (action, data) {
                if (action != 'ok') return;
                self.config.dataSources[type][index]=data;
            });
        }
	},
	watch:{
		"config.styles.yAxisShow2":function (val){
			//开启双y轴
			if(val && !this.config.dataSources.measures2){
                this.config.dataSources["measures2"]=[];
			}
		}
	}
}
